import { defineStore } from "pinia";

export type Widget = {
  name: string;
  component: string;
  icon: string;
  field?:{
    [keyof:string]:any
  }
};
export type WidgetWithId = Widget & { id: number | string };
export type WidgetsState = {
  initializing: Widget[];
  dragstatus: boolean; // 拖拽状态
  PanelList: WidgetWithId[];
  currentComponent: WidgetWithId | null;
  dragOverIndex:number|undefined
};

export const useWidgetsStore = defineStore("widgets", {
  state: (): WidgetsState => ({
    initializing: [],
    dragstatus: false,
    PanelList: [],
    currentComponent: null,
    dragOverIndex:undefined
  }),
  actions: {
    changeDragstatusAction(status: boolean) {
      this.dragstatus = status;
    },
    dragOverIndexAction(index: number) {
      this.dragOverIndex = index;
    },
    pushinitializingAction(item: Widget) {
      this.initializing.push(item);
    },
    setCurrentComponentAction(item: WidgetWithId) {
      this.currentComponent = item;
    },
  },
});
